<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="Public/Bootstrap/Css/bootstrap.min.css" />
	<link rel="stylesheet" href="Public/css.css" />
	
	<style type="text/css">
		body{
			margin-bottom: 100px;
		}
	</style>
	<script type="text/javascript" src="Public/js/jquery-1.8.2.min.js"></script>
	
	    	
</head>
<body>
	<!--546464646464654646--> 
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">

		<form action="<?php echo U('add')?>" method='post'>
		<table class='table table-bordered table-hover'>
			<tr>
				<th>货品ID</th>				
			    <?php foreach ($attr as $v){?>
					<th><?php echo $v['naname']?></th>
				<?php }?>
			    <td>库存</td>
			    <td>货号</td>						
				<th>操作</th>
			</tr>
			  
			 <?php foreach ($kindData as $v){?>
				<tr class="info">
					<td><?php echo $v['hid']?></td>
					<?php foreach ($v['groupid'] as $vv){?>
						<td><?php echo $vv?></td>
					<?php }?>
					<td><?php echo $v['stock']?></td>
					<td><?php echo $v['art']?></td>
					<td>
						<a href="<?php echo U('edit',array('hid'=>$v['hid'],'gid'=>$_GET['gid']))?>" class="btn btn-warning"><i class="icon-pencil icon-white"></i>修改</a>
						<a href="javascript:if(confirm('确认要删除吗？')) location.href='<?php echo U('del',array('hid' => $v['hid']))?>';" class="btn btn-danger"><i class="icon-trash icon-white"></i>删除</a>
					</td>
				</tr>
			<?php }?>

			
			<tr class="info">
				<td>添加货品</td>
		
				<?php foreach ($attr as $v){?>
					<td>
						<select name="groupid[]">
							<option value="0">-请选择-</option>
							
							<?php foreach ($v['nazhi'] as $vv){?>
								<option value="<?php echo $vv['gsid']?>"><?php echo $vv['sxzhi']?></option>
							<?php }?>
						</select>
					</td>
				<?php }?>
									
				<td>
					<input type="text" name= "stock"/>
				</td>
				<td>
					<input type="text" name='art'  />
				</td>
				<td></td>
			</tr>				
			
		</table>
			<tr>
				<input type="hidden" name='gid' value='<?php echo $_GET['gid']?>'/>
				<!--<input type="hidden" name='tid' value='{$Think.get.tid}'/>-->
				<input type="submit" value='保存添加' class="btn btn-primary"/>			
			</tr>
	</form>

	</div>
	</div>
	</div>


<script type="text/javascript">
	var sel = $('select[name="spec[]"]');
	var len = sel.length;
	sel.change(function () {
		var remote = {
			'gid' : <?php echo Q('get.gid')?>,
			'spec' : {}
		};
		for (var i = 0; i < len; ++i)
		{
			if (sel.eq(i).val() == 0)
			{
				return;
			}
			else
			{
				remote.spec[i] = sel.eq(i).val();
			}
		}
		$.ajax({
			url : '<?php echo U('GoodsList/check')?>',
			type : 'get',
			data : remote,
			dataType : 'json',
			success : function(data)
			{
				if (data == 0)
				{
					alert('货品已存在，如果要修改库存，请点击修改');
					for (var i = 0; i < len; ++i)
					{
						sel.eq(i).val(0);
					}
				}
			}
		});
	});
</script>

</body>
</html>